<template>
<div class="container__">
    <div class="topmony">
        <!-- <img src="/static/images/1.png" alt=""> -->
        <div class="posmoney">
            <h3>账户余额</h3>
            <div class="flexbox">
                <div>
                    <span class="mone"><span v-if="info.jifen">{{info.jifen}}</span> <span v-else>0</span></span>
                    <span class="tex">积分</span>
                </div>
                <div>
                    <span class="mone">￥ <span v-if="info.balance">{{info.balance}}</span> <span v-else>0</span></span>
                    <span class="tex">余额</span>
                </div>
            </div>
        </div>
    </div>
    <van-tabs :active="show" @change="onChange" :line-width="173">
        <van-tab title="积分收益"></van-tab>
        <van-tab title="我的收益"></van-tab>
    </van-tabs>
    <scroll-view :scroll-y="true" style="height: 330px;" @scrolltolower="scrolltolower" :lower-threshold="0">
        <van-cell v-if="tixianlist" use-label-slot v-for="(item, index) in tixianlist" :key="index">
            <view class="title" slot="title">{{item.remark}}</view>
            <view class="lable" slot="label">
                <span>{{item.created_at}}</span>
            </view>
            <view class="value">
                <span v-if="item.change==2">-</span><span v-if="item.change==1">+</span><span >{{item.money}}</span></view>
        </van-cell>
        <view v-if="loading">{{LoadingText}}</view>
        <div class="que" v-if="isempty"><img :src="img+'/que/no_money@2x.png'" alt=""></div>
    </scroll-view>
    <div class="button" @click="toCash">
        提现
    </div>
</div>
</template>

<script>
import {
    mywallet
} from '@/api/my'
import {
    walletlist
} from '@/api/my'
import {
    jifenlist
} from '@/api/my'
export default {
    data() {
        return {
            show: 0,
            tixianlist: [],
            info: {},

            isnull: true,
            loading: false,
            LoadingText: 'Loading More',
            loadingmore: true,
            Page: 1,
            last_page: '',
            isempty:false,
             img:this.$URL.imgurl,
             type:1
        }
    },
    methods: {
        onChange(e) {
            this.show = e.target.index
            this.type=e.target.index+1
            this.tixianlist = []
            this.isnull = true
            this.Page = 1
            this.getlist()
        },
        toCash() {
            wx.navigateTo({
                url: '/pages/cash/main'
            })
        },
        getinfo() {
            mywallet().then(res => {
                this.info = res.data
            })
        },
        getlist() {
            this.isempty=false
            walletlist({
                page: this.Page,
                type: this.type
            }).then(res => {
                if(res.code==200){
                    if (res.data.last_page < this.Page) return
                    this.last_page = res.data.last_page
                    this.tixianlist = this.isnull ? res.data.data : this.tixianlist.concat(res.data.data)
                    this.isnull = false
                }else if(res.code==201){
                    this.isempty=true
                }
                
            }).catch(err=>{
                this.isempty=true
            })
        },
        scrolltolower() {
            if (this.Page >= this.last_page) return
            this.loading = true
            this.Page += 1
            this.getlist()
            this.loading = false
        }

    },
    mounted() {
        Object.assign(this.$data, this.$options.data())
        this.show = parseInt(this.$root.$mp.query.type)
    },

    onShow() {
        this.isnull = true
         this.isempty=false
        this.tixianlist = []
        this.Page = 1
        
        this.getlist()
        this.getinfo()
    },
    onUnload(){
        
    },
}
</script>

<style lang="scss">
.container__ {
    background-color: #fff;
    min-height: 100vh;
    font-size: 16px;
    // padding: 40px 15px;
    box-sizing: border-box;
    .que {
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100%;
        img{
            width: 203px ;
            height: 162px;
        }
    }
    .van-cell {
        align-items: center;
    }

    .title {
        font-size: 14px;
        color: #000
    }

    .lable {
        font-size: 12px;
    }

    .value {
        font-size: 14px;
        color: #000
    }

    .button {
        width: 345px;
        height: 45px;
        background: #46B7FF;
        border-radius: 5px;
        margin: 10px auto 0;
        color: #fff;
        font-size: 16px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .quesheng {
        min-height: 250px;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .van-tabs__nav {
        height: 38px;
        font-size: 15px;
    }

    .van-tabs--line .van-tabs__wrap {
        height: 38px;
        box-shadow: 0px 2px 5px 0px rgba(0, 0, 0, 0.07);
    }

    .van-ellipsis {
        height: 38px;
        font-weight: bold;
    }

    .van-tabs__line {
        // width: 173px!important;
        height: 2px;
        background: rgba(70, 183, 255, 1);
        border-radius: 1px;
    }

    .topmony {
        // img{
        //     position: absolute;
        //     left: 0;
        //     width: 100%;
        //      z-index: 0;
        // }
        height: 154px;
        position: relative;
        background-color: #ddd;
        background: url('../../../static/images/1.png') no-repeat;
        background-size: contain;
        // background-position: center;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        justify-content: flex-end;
        align-items: center;
        padding: 0 0 15px 0;

        .posmoney {
            z-index: 1;
            position: relative;
            width: 345px;
            height: 110px;
            background: #fff;
            box-shadow: 0px 0px 5px 0px rgba(0, 0, 0, 0.3);
            border-radius: 5px;
            box-sizing: border-box;
            padding: 11px 15px 0;

            h3 {
                color: #666666;
                font-size: 15px;
            }

            .flexbox {
                display: flex;
                justify-content: space-around;
                padding: 20px 20px 0;

                div {
                    width: 50%;
                    box-sizing: border-box;
                    display: flex;
                    justify-content: space-around;
                    align-items: center;
                    flex-direction: column;

                    span {
                        line-height: 25px;
                    }

                    .mone {
                        font-size: 20px;
                        color: rgba(70, 183, 255, 1);
                    }

                    .tex {
                        font-size: 14px;
                        color: rgba(102, 102, 102, 1);
                        font-weight: 500;
                    }
                }
            }
        }
    }
}
</style>
